package com.hylanda.pb.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import com.hylanda.pb.dao.ReportFileDao;
import com.hylanda.pb.entity.ReportFile;
import com.hylanda.pb.model.ReportFileQo;

/** 	
 * @author zhangy
 * @E-mail:blackoon88@gmail.com 
 * @qq:846579287
 * @version created at：2018年2月6日 上午10:47:41 
 * note
 */
@Service
public class ReportFileService {
	@Autowired
    private ReportFileDao reportFileDao;
	
	public String findById(Long id) {
		return reportFileDao.findOne(id);
	}

	public String findByName(String name){
		return reportFileDao.findByName(name);
	}
	
	public ReportFile create(ReportFile entity) {
		  return reportFileDao.save(entity);
	}

	public ReportFile update(ReportFile entity) {
		return reportFileDao.save(entity);
	}

	public int delete(Long id) {
		return reportFileDao.delete(id);
	}

	public Page<ReportFile> findPage(ReportFileQo reportFileQo){
		Page<ReportFile> page=reportFileDao.findPage(reportFileQo);
		return page;
	}
	
	
	
	
//	public Page<ReportFile> findPage(ReportFileQo reportFileQo) {
//		List<ReportFile> reportFiles=reportFileDao.findAll();
//		Pageable pageable = new PageRequest(reportFileQo.getPage(), reportFileQo.getSize());
//		Page<ReportFile> pp=reportFileDao.findID("1",pageable);
//		return pp;
//	    return reportFileDao.findAll(pageable);
//	}
	
	
//	public  Page<ReportFile> findPageCriteria(ReportFileQo reportFileQo){
//		Pageable pageable = new PageRequest(reportFileQo.getPage(), reportFileQo.getSize(), Sort.Direction.ASC, "id");  
//		Pageable pageable = new PageRequest(reportFileQo.getPage(), reportFileQo.getSize(), new Sort(Sort.Direction.ASC, "id"));
//        Page<ReportFile> rfPage = reportFileDao.findAll(new Specification<ReportFile>(){  
//            @Override  
//            public Predicate toPredicate(Root<ReportFile> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {  
//                List<Predicate> list = new ArrayList<Predicate>();  
//                if(null!=reportFileQo.getName()&&!"".equals(reportFileQo.getName())){  
//                    list.add(criteriaBuilder.equal(root.get("name").as(String.class), bookQuery.getName()));  
//                }  
//                if(null!=reportFileQo.getIsbn()&&!"".equals(reportFileQo.getIsbn())){  
//                    list.add(criteriaBuilder.equal(root.get("isbn").as(String.class), bookQuery.getIsbn()));  
//                }  
//                if(null!=reportFileQo.getAuthor()&&!"".equals(reportFileQo.getAuthor())){  
//                    list.add(criteriaBuilder.equal(root.get("author").as(String.class), bookQuery.getAuthor()));  
//                }  
//                Predicate[] p = new Predicate[list.size()]; 
//                return criteriaBuilder.and(list.toArray(p));
                
//                Predicate p1 = criteriaBuilder.equal(root.get("name").as(String.class), reportFileQo.getName());  
//                Predicate p2 = criteriaBuilder.equal(root.get("isbn").as(String.class), reportFileQo.getIsbn());  
//                Predicate p3 = criteriaBuilder.equal(root.get("author").as(String.class), reportFileQo.getAuthor());  
//                query.where(criteriaBuilder.and(p1,p2,p3));  
//                return query.getRestriction();  
//            }  
//        },pageable);
//        return rfPage; 
//	}
	
}
